import Notify from '../../miniprogram_npm/vant-weapp/notify/notify';
wx.cloud.init()
const db = wx.cloud.database({});
Page({
  data: {
    value: '',
    active: 1,
    tabs: ['关键词','待审核','审核已通过','审核不通过'],
    tagList: []
  },
  onChange(e) {
    this.setData({
      value: e.detail
    });
  },
  onSearch() {
    wx.showToast({
      icon: "loading",
      title: '搜索' + this.data.value
    })
  },
  onClick() {
    wx.showToast({
      icon: "loading",
      title: '搜索' + this.data.value
    })
  },
  changetab(event) {
    this.setData({
      active: event.detail.index
    })
    
    this.getTagList()
  },
  toDetail(event) {
    let legueDetail = JSON.stringify(event.currentTarget.dataset.leguedetail)
    wx.navigateTo({
      url: '../legue/leguereviewdetail?legueDetail=' + legueDetail,
    })
  },
  getTagList() {
    wx.showLoading({
      title: '加载中....',
    })
  
    wx.cloud.callFunction({
      name: 'getLegueReview',
      data :{
        tag: this.data.tabs[this.data.active],
        active: this.data.active,
        value: this.data.value
      },
      complete: res => {
        wx.hideLoading()
        this.setData({
          tagList: res.result.data
        })
        if(this.data.active == 0) {
          if(this.data.value == '' || this.data.tagList.length == 0) {
            this.setData({
              tagList: []
            })
            wx.showToast({
              icon:"none",
              title: '输入关键词试试看',
            })
          }
        }
      }
    })
  },
  
  search() {
    this.setData({
      active: 0
    })
    this.getTagList()
  },
  
  onLoad: function (options) {
    this.getTagList()
  },
}); 

